<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>审核结果判断</title>
    <script src="../../res/layui/layui.js"></script>
    <link rel="stylesheet" href="../../res/layui/css/layui.css" type="text/css">
    <script src="../../res/js/Tools.js" charset="utf-8"></script>
    <script src="../../res/js/jquery-3.1.1.min.js" charset="utf-8"></script>
</head>
<body>
<form class="layui-form" action="" lay-filter="example" id="newsForm">
    <input type="hidden" id="auditresult" name="auditresult">
    <div class="layui-form-item layui-form-text" id="newtext">
        <label class="layui-form-label">意见：</label>
        <div class="layui-input-block">
            <textarea placeholder="请输入内容" class="layui-textarea" id="auExp" name="auExp"></textarea>
        </div>
    </div>
    <div class="layui-form-item" id="watch">
        <label class="layui-form-label">可观看：</label>
        <div  class="layui-input-block" id="userLook">

        </div>
    </div>
    <div class="layui-form-item" id="submiting">
        <div class="layui-input-block">
            <input type="button" class="layui-btn" value="通过" id="submit">
            <input type="button" class="layui-btn layui-btn-danger" value="驳回" id="refuse">
        </div>
    </div>
</form>
<script>
    //全局同步
    $.ajaxSetup({
        async:false
    });

    var attachId=getQueryString("attachId");
    var auditState=getQueryString("auditState");
    var attachType=getQueryString("attachType");
    var remark=getQueryString("remark");
    var attachPublisher=getQueryString("attachPublisher");
    function submitJt(){
        $("#submit").click(function(){
            var url="../../AtsAttachmentAction/audit";
            var data={attachId:attachId,auditState:auditState,attachType:attachType,remark:remark,auExp:$("#auExp").val()};
            $.post(url,data,function(obj){
                if(obj.num==1){
                    layer.msg(obj.msg, {
                        icon: 1,
                        time: 1000,
                    }, function () {
                        var indexs = parent.layer.getFrameIndex(window.name);
                        parent.layer.close(indexs);
                    });
                    return false;
                }else{
                    layer.msg("审核失败");
                }
                table2.reload();
            })
        })
    }
    //复选框选中人员
    function userselect() {
        var url = "../../AtsAttachmentAction/userAll";
        $.post(url, null, function (obj) {
            $.each(obj, function (index, item) {
                $("#userLook").append("<div id='"+item.userId+"'><input type='checkbox' name='userId' value='"+item.userId+"."+item.userName+"' checked='' title='"+item.userName+"'></div>");
            })
        }, 'json')
        $("input[name='userId']:checked").each(function(indexs,items){
            if($(this).val().indexOf(attachPublisher)==-1){
                $(this).attr('checked',false);
            }
        });
    }
    //驳回提交的方法
    function fromrefuse() {
        layui.use(['form', 'layedit', 'laydate','upload'], function(){
                var layer=layui.layer;
                $("#refuse").click(function () {
                    if($("#auExp").val()!=null){
                        var url="../../AtsAttachmentAction/updateState";
                        var data={attachId:attachId,auditState:25,attachContent:$("#attachContent").val(),attachType:attachType};
                        $.post(url,data,function(obj){
                            if(obj.num==1){
                                layer.msg(obj.msg, {
                                    icon: 1,
                                    time: 1000,
                                }, function () {
                                    var indexs = parent.layer.getFrameIndex(window.name);
                                    parent.layer.close(indexs);
                                });
                                return false;
                            }else{
                                layer.msg(obj.msg);
                            }
                        });
                    }else{
                        layer.msg("请填写驳回原因");
                    }
                });
            }
        )}
    $(function(){
        $("#auditresult").val(20);
        $("#watch").hide();//隐藏
        submitJt();//审核通过监听
        userselect();//显示自身人员
        fromrefuse();//表单提交
    })
</script>
</body>
</html>